"""
抽象类 / 方法重写 / 多态

Version: 0.1
Author: yuwl
Date：2024-3-28
"""

from abc import ABCMeta, abstractmethod

class Employee(object, metaclass=ABCMeta):

    def __init__(self, name):
        self._name = name

    @property
    def name(self):
        return self._name
    
    @abstractmethod
    def get_salary(self):
        pass


class Manager(Employee):

    # 想一想，如果不定义构造方法会怎么样，可以不定义
    # def __init__(self, name):
        # 想一想，如果不调用父类构造器会怎么样，可以不调用，但得自己重写 self._name = name
        # super().__init__(name)

    def get_salary(self):
        return 12000
    

class Programmer(Employee):

    def __init__(self, name):
        super().__init__(name)

    def set_working_hour(self, working_hour):
        self._working_hour = working_hour

    def get_salary(self):
        return 100 * self._working_hour
    

class Salesman(Employee):

    def __init__(self, name):
        super().__init__(name)

    def set_sales(self, sales):
        self._sales = sales

    def get_salary(self):
        return 1500 + self._sales * 0.05
    

if __name__ == '__main__':
    emps = [Manager('武则天'), Programmer('狄仁杰'), Salesman('李元芳')]
    for emp in emps:
        if isinstance(emp, Programmer):
            working_hour = int(input('请输入%s本月工作时间：' % emp.name))
            emp.set_working_hour(working_hour)
        elif isinstance(emp, Salesman):
            sales = float(input('请输入%s本月销售额：' % emp.name))
            emp.set_sales(sales)
        print('%s本月月薪为：￥%.2f元' % (emp.name, emp.get_salary()))